/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Gui;

import Params.ChatMessage;
import Params.ClientHandler;
import Params.ServerSocketItem;
import Params.SocketListener;
import Params.ThreadConnectionSocketCapture;
import Params.ThreadConnectionSocketChat;
import Params.ThreadConnectionSocketRemoteDesktop;
import Params.ThreadConnectionSocketSendFile;
import Params.ThreadConnectionSocketSendMessages;
import Params.ThreadConnectionSocketSendShell;
import Params.ThreadConnectionSocketSpyScreen;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;

/**
 *
 * @author ANH PHONG
 */
public class MainSever extends javax.swing.JFrame implements ActionListener, SocketListener, Runnable {

    /**
     * Creates new form MainSever
     */
    public ArrayList<ChatFormServer> List_CSChat = new ArrayList<ChatFormServer>();
    public ArrayList<frmCaptureClient> List_CSCapture = new ArrayList<frmCaptureClient>();
    public ArrayList<frmSreenClient> List_CSSpy = new ArrayList<frmSreenClient>();
    public ArrayList<frmRemoteDesktop> List_CSRemote = new ArrayList<frmRemoteDesktop>();
    public ArrayList<frmCMD> List_CSCMD = new ArrayList<frmCMD>();
    public static String strPort = "1234";
    public static Vector listConnection;
   
    DefaultListModel Lan_client_chat = new DefaultListModel();

    public MainSever() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        btnStart = new javax.swing.JButton();
        btnStop = new javax.swing.JButton();
        btnChat = new javax.swing.JButton();
        btnRemote = new javax.swing.JButton();
        btnScreenCapture = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        btnExits = new javax.swing.JButton();
        jSplitPane2 = new javax.swing.JSplitPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jListChat = new javax.swing.JList();
        jdpDesktop = new javax.swing.JDesktopPane();
        jbtnsendmessage = new javax.swing.JButton();
        jbtnshellClient = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/logo.png"))); // NOI18N
        jLabel1.setText("LAN SUPPORT");

        btnStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/player_play.png"))); // NOI18N
        btnStart.setText("Start");
        btnStart.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStartActionPerformed(evt);
            }
        });

        btnStop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/player_pause.png"))); // NOI18N
        btnStop.setText("Stop");
        btnStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStopActionPerformed(evt);
            }
        });

        btnChat.setText("Chat");
        btnChat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChatActionPerformed(evt);
            }
        });

        btnRemote.setText("Remote desktop");
        btnRemote.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnRemote.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoteActionPerformed(evt);
            }
        });

        btnScreenCapture.setText("Screen Capture");
        btnScreenCapture.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnScreenCapture.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnScreenCaptureActionPerformed(evt);
            }
        });

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/display.png"))); // NOI18N
        jButton6.setText("Monitor Screen");
        jButton6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/file_trans.png"))); // NOI18N
        jButton9.setText("Send File");
        jButton9.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        btnExits.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/exit.png"))); // NOI18N
        btnExits.setText("Exits");
        btnExits.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnExits.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitsActionPerformed(evt);
            }
        });

        jPanel3.setLayout(new java.awt.BorderLayout());

        jScrollPane2.setViewportView(jListChat);

        jPanel3.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jSplitPane2.setLeftComponent(jPanel3);
        jSplitPane2.setRightComponent(jdpDesktop);

        jbtnsendmessage.setText("Send Message");
        jbtnsendmessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnsendmessageActionPerformed(evt);
            }
        });

        jbtnshellClient.setText("Shell Client");
        jbtnshellClient.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnshellClientActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSplitPane2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnStart)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnStop)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnChat, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnsendmessage)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnRemote)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnScreenCapture)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnshellClient)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnExits)
                        .addGap(0, 36, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnStart, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnStop, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnChat, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRemote, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnScreenCapture, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnExits, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnsendmessage, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnshellClient, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //</editor-fold>

    @Override
    public void run() {
        try {
            ServerSocket SocketChat = new ServerSocket(Integer.parseInt(strPort));
            ServerSocket SocketSendMessages = new ServerSocket(Integer.parseInt(strPort) + 1);
            ServerSocket SocketSendFile = new ServerSocket(Integer.parseInt(strPort) + 2);
            ServerSocket SocketCapture = new ServerSocket(Integer.parseInt(strPort) + 3);
            ServerSocket SocketSpy = new ServerSocket(Integer.parseInt(strPort) + 4);
            ServerSocket SocketShell = new ServerSocket(Integer.parseInt(strPort) + 5);
            ServerSocket SocketRemote = new ServerSocket(Integer.parseInt(strPort) + 6);
            listConnection = new Vector();
            while (true) {
                ServerSocketItem tempServer = new ServerSocketItem();
                Socket client = SocketChat.accept();
                Socket clientm = SocketSendMessages.accept();
                Socket clients = SocketSendFile.accept();
                Socket clientc = SocketCapture.accept();
                Socket clientspy = SocketSpy.accept();
                Socket clientshell = SocketShell.accept();
                Socket clientremote = SocketRemote.accept();
                
                tempServer.setSOCK(client);
                tempServer.setSOCKM(clientm);
                tempServer.setSOCKS(clients);
                tempServer.setSockcapture(clientc);
                tempServer.setSockspy(clientspy);
                tempServer.setSockshell(clientshell);
                tempServer.setSockremote(clientremote);
                if (client != null) {
                    Lan_client_chat.addElement(client);
                    tempServer.setConnectionChat(new ThreadConnectionSocketChat(client, this));
                    tempServer.setConnectionMessages(new ThreadConnectionSocketSendMessages(clientm, this));
                    tempServer.setConnectionSocketSendFile(new ThreadConnectionSocketSendFile(clients, this));
                    tempServer.setConnectionCapture(new ThreadConnectionSocketCapture(clientc, this));
                    tempServer.setConnectionSpy(new ThreadConnectionSocketSpyScreen(clientspy, this));
                    tempServer.setConnectionshell(new ThreadConnectionSocketSendShell(clientshell, this));
                    tempServer.setConnectionremote(new ThreadConnectionSocketRemoteDesktop(clientremote, this));
                }
                listConnection.addElement(tempServer);
                jListChat.setModel(Lan_client_chat);
                Thread.yield();
            }
        } catch (IOException ex) {
            Logger.getLogger(MainSever.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //<editor-fold defaultstate="collapsed" desc="Exit">
    private void btnExitsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitsActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnExitsActionPerformed
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Start Server">

    private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
        // TODO add your handling code here:
        frmPortServerDialogue frmport_server = new frmPortServerDialogue(this, rootPaneCheckingEnabled);
        frmport_server.setVisible(true);

        if (frmport_server.getReturnStatus() == 1)//khi click button ok thì method getReturnStatus() trả về 1
        {
            strPort = frmport_server.txtport.getText();
        } else {
            return;
        }
        initServer();
    }//GEN-LAST:event_btnStartActionPerformed
//</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Stop">

    private void btnStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnStopActionPerformed
//</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Chat">

    private void btnChatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChatActionPerformed
        // TODO add your handling code here:
        Socket temp = (Socket) jListChat.getSelectedValue();
        ChatFormServer FormChat = new ChatFormServer(strPort, temp);
        FormChat.setVisible(true);
        this.jdpDesktop.add(FormChat);            // TODO add your handling code here:
        List_CSChat.add(FormChat);
       
    }//GEN-LAST:event_btnChatActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        // TODO add your handling code here:
        Socket temp = (Socket) jListChat.getSelectedValue();
        frmSendFile _senfile = new frmSendFile(temp);
        _senfile.setVisible(true);
        this.jdpDesktop.add(_senfile);
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jbtnsendmessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnsendmessageActionPerformed
        // TODO add your handling code here:
        Socket temp = (Socket) jListChat.getSelectedValue();
        frmSendMessage _Messages = new frmSendMessage(temp);
        _Messages.setVisible(true);
        this.jdpDesktop.add(_Messages);
    }//GEN-LAST:event_jbtnsendmessageActionPerformed

    private void btnRemoteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoteActionPerformed
        // TODO add your handling code here:
         try {
            // TODO add your handling code here:
            Socket temp = (Socket) jListChat.getSelectedValue();

            frmRemoteDesktop frmremote_server = new frmRemoteDesktop(strPort, temp);
            frmremote_server.setVisible(true);
            this.jdpDesktop.add(frmremote_server);
            List_CSRemote.add(frmremote_server);
        } catch (InterruptedException ex) {
            Logger.getLogger(MainSever.class.getName()).log(Level.SEVERE, null, ex);
        }
    
    }//GEN-LAST:event_btnRemoteActionPerformed

    private void btnScreenCaptureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnScreenCaptureActionPerformed
        // TODO add your handling code here:
       try {
            // TODO add your handling code here:
            Socket temp = (Socket) jListChat.getSelectedValue();
            frmCaptureClient frmcapture_Server = new frmCaptureClient(strPort, temp);
            frmcapture_Server.setVisible(true);
            this.jdpDesktop.add(frmcapture_Server);
            List_CSCapture.add(frmcapture_Server);
        } catch (InterruptedException ex) {
            Logger.getLogger(MainSever.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnScreenCaptureActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        try {
            // TODO add your handling code here:
            Socket temp = (Socket) jListChat.getSelectedValue();

            frmSreenClient frmcspyapture_Server = new frmSreenClient(strPort, temp);
            frmcspyapture_Server.setVisible(true);
            this.jdpDesktop.add(frmcspyapture_Server);
            List_CSSpy.add(frmcspyapture_Server);
        } catch (InterruptedException ex) {
            Logger.getLogger(MainSever.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jbtnshellClientActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnshellClientActionPerformed
        // TODO add your handling code here:
         Socket temp = (Socket) jListChat.getSelectedValue();
        frmCMD frmshell_Server = new frmCMD(temp);
        frmshell_Server.setVisible(true);
        this.jdpDesktop.add(frmshell_Server);
        List_CSCMD.add(frmshell_Server);
    }//GEN-LAST:event_jbtnshellClientActionPerformed
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Ham Main">

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainSever.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainSever.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainSever.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainSever.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainSever().setVisible(true);
            }
        });
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Khoi tao Server">

    private void initServer() {
         try {
            Thread thread = new Thread(this);
            thread.start();
        } catch (Exception ex) {
            Logger.getLogger(MainSever.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //</editor-fold>
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChat;
    private javax.swing.JButton btnExits;
    private javax.swing.JButton btnRemote;
    private javax.swing.JButton btnScreenCapture;
    private javax.swing.JButton btnStart;
    private javax.swing.JButton btnStop;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jListChat;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JButton jbtnsendmessage;
    private javax.swing.JButton jbtnshellClient;
    private javax.swing.JDesktopPane jdpDesktop;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void onStart() {
    }

    ;

    @Override
    public void onStop() {
        throw new UnsupportedOperationException("Not supported yet.");
    }  
    @Override
    public void onRead(ChatMessage message) {

        if (message.getType() == 1) {
            for (int i = 0; i < List_CSChat.size(); i++) {
                int temp2 = Integer.parseInt(message.getName());
                int temp = List_CSChat.get(i)._sockhientai.getPort();
                if (temp == temp2) {
                    if ("exit_1".equals(message.getMessage())) {
                        List_CSChat.get(i).dispose();
                        Socket _socktemp = List_CSChat.get(i)._sockhientai;
                        for (int j = 0; j < Lan_client_chat.size(); j++) {
                            Socket _socktemp2 = (Socket) Lan_client_chat.get(j);
                            if (_socktemp2 == _socktemp) {
                                Lan_client_chat.remove(j);
                                break;
                            }
                        }
                    } else {
                        List_CSChat.get(i).onRead(message);
                    }
                }
            }

        }
        if (message.getType() == 3) {
            for (int i = 0; i < List_CSCapture.size(); i++) {
                int temp2 = Integer.parseInt(message.getName());
                int temp = List_CSCapture.get(i)._sockhientai.getPort();
                if (temp + 2 == temp2) {
                    List_CSCapture.get(i).onRead(message);
                }
            }
        }
        if (message.getType() == 4) {
            for (int i = 0; i < List_CSSpy.size(); i++) {
                int temp2 = Integer.parseInt(message.getName());
                int temp = List_CSSpy.get(i)._sockhientai.getPort();
                if (temp + 3 == temp2) {
                    List_CSSpy.get(i).onRead(message);
                }
            }

        }
        if (message.getType() == 5) {
            for (int i = 0; i < List_CSCMD.size(); i++) {
                int temp2 = Integer.parseInt(message.getName());
                int temp = List_CSCMD.get(i)._sockdangchon.getPort();
                if (temp + 4 == temp2) {
                    List_CSCMD.get(i).onRead(message);
                }
            }

        }
        if (message.getType() == 6) {
            for (int i = 0; i < List_CSRemote.size(); i++) {
                int temp2 = Integer.parseInt(message.getName());
                int temp = List_CSRemote.get(i)._sockhientai.getPort();
                if (temp + 5 == temp2) {
                    List_CSRemote.get(i).onRead(message);
                }
            }

        }

    }
}
